from langgraph_sdk import get_client
import asyncio
from langgraph_sdk.schema import Command

client = get_client(url="http://127.0.0.1:2024")
# client = get_client(url="http://192.168.0.101:2024")
# client = get_client(url="http://127.0.0.1:2025")

assistant_id = "review1"

async def main():
    thread = await client.threads.create()
    thread_id = thread["thread_id"]
    print("thread_id", thread_id)

    async for chunk in client.runs.stream(
        thread_id,
        assistant_id,
        input={
        "messages": [{
            "role": "human",
            "content": "book a stay at McKittrick hotel",
            }],
        },
    ):
        # print(f"Receiving new event of type: <{chunk.event}>")
        print(chunk)
        print("\n")
        # if chunk.event == "metadata":
        #     print(chunk)
        #     print("\n")

        # if chunk.data:
        #     array = chunk.data.get("messages")
        #     if array:
        #         # print("============================================")
        #         # print(len(array))
        #         last_msg = array[-1]
        #         has_tools = False
        #         if last_msg.get("tool_calls"):
        #             has_tools = True
        #         print(f"type: {last_msg['type']}, content: {last_msg['content']},  has-tools: {has_tools}")
        #         print("\n")

    print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    async for chunk in client.runs.stream(
        thread_id,
        assistant_id,
        # command=Command(resume=[{"type": "accept"}]),
        command=Command(resume=[{"type": "edit", "args": {"args": {"hotel_name": "HollyWin Hotel"}}}]),
    ):
        print(f">>>>>>>>>>> Receiving new event of type: <{chunk.event}>")
        # print(chunk)
        if chunk.data:
            array = chunk.data.get("messages")
            if array:
                last_msg = array[-1]
                print(last_msg)
                print("\n")


asyncio.run(main())
